function deepCopy(obj) {
    let newObj = obj instanceof Array ? [] : {};
    // 如何不遍历原型链上的属性,obj.hasOwnProperty(key)
    for(let key in obj) {
        // if (obj[key] instanceof Object) {
        //     newObj[key] = deepCopy(obj[key]);
        // }else if (obj.hasOwnProperty(key)) {
        //         newObj[key] = obj[key]; 
        // } 
    //简化版
    if (obj.hasOwnProperty(key)) {
        newObj[key] = obj[key] instanceof Object ? deepCopy(obj[key]) : obj[key];
    }
    }
    return newObj;
}
let person = {
    name:"tom",
    age:20,
    like: {
        sports:'running',
        food:'beef'
    }
};
let newPerson = deepCopy(person);
person.name = 'jack'
person.like.sports = 'playing'
console.log(newPerson);